package exercises.Charpter10;

import java.util.Random;

interface Gamble{
	Boolean win();
}

interface GambleFactory{
	Gamble getGamble();
}

class CoinFactory implements GambleFactory{

	@Override
	public Gamble getGamble() {
		return new Gamble(){
			@Override
			public Boolean win() {
				Random rand = new Random();
				boolean win = rand.nextBoolean();
				return win;
			}
		};
	}
}

class DiceFactory implements GambleFactory{

	@Override
	public Gamble getGamble() {
		return new Gamble(){
			@Override
			public Boolean win() {
				Random rand = new Random();
				boolean win = rand.nextBoolean();
				return win;
			}
		};
	}
}

public class Seventeen {
	public static void playGamble(GambleFactory gambleFactorys){
		Gamble myGamble = gambleFactorys.getGamble();
		if (myGamble.win())
			System.out.println("Win");
		else {
			System.out.println("Lose");
		}
	}
	
	public static void main(String[] args){
		playGamble(new CoinFactory());
		playGamble(new DiceFactory());
	}
}
